/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Compra.java
 *
 * Created on 26-nov-2010, 23:18:28
 */

package ejemplotiendawebswing;

import ejemplotiendaweb.controlador.CompraController;
import javax.swing.JComboBox;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author ccia
 */
public class Compra extends javax.swing.JDialog {

    private CompraController controlador;


    /** Creates new form Compra */
    public Compra(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    public Compra(Principal gui, boolean b) {
        super(gui, b);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        labelMonto = new javax.swing.JLabel();
        btnComprar = new javax.swing.JButton();
        jToolBar1 = new javax.swing.JToolBar();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        comboClientes = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaPedido = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Compra Actual");

        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 12, 12));

        jLabel1.setText("Total de Compra: $");
        jPanel1.add(jLabel1);

        labelMonto.setText("0");
        jPanel1.add(labelMonto);

        btnComprar.setText("Comprar");
        btnComprar.setFocusable(false);
        btnComprar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnComprar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnComprar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnComprarActionPerformed(evt);
            }
        });
        jPanel1.add(btnComprar);

        jToolBar1.setRollover(true);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ejemplotiendawebswing/resources/delete.png"))); // NOI18N
        jButton1.setText("Eliminar");
        jButton1.setFocusable(false);
        jButton1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton1.setMaximumSize(new java.awt.Dimension(53, 41));
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton1);

        jLabel2.setText("Cliente:");
        jToolBar1.add(jLabel2);

        comboClientes.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        comboClientes.setAlignmentX(0.3F);
        comboClientes.setAlignmentY(0.3F);
        comboClientes.setAutoscrolls(true);
        comboClientes.setMinimumSize(new java.awt.Dimension(40, 10));
        jToolBar1.add(comboClientes);

        jPanel1.add(jToolBar1);

        tablaPedido.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Producto", "Cantidad", "Total"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Object.class, java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                false, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tablaPedido.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        tablaPedido.setMinimumSize(new java.awt.Dimension(20, 0));
        tablaPedido.setPreferredSize(new java.awt.Dimension(20, 0));
        tablaPedido.setRowHeight(10);
        tablaPedido.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(tablaPedido);

        jPanel1.add(jScrollPane1);

        getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        controlador.eliminarProducto(tablaPedido.getSelectedRow());
    }//GEN-LAST:event_jButton1ActionPerformed

    private void btnComprarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnComprarActionPerformed
        controlador.generarCompra();
    }//GEN-LAST:event_btnComprarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnComprar;
    private javax.swing.JComboBox comboClientes;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JLabel labelMonto;
    private javax.swing.JTable tablaPedido;
    // End of variables declaration//GEN-END:variables

    public DefaultTableModel getModel() {
        return (DefaultTableModel) tablaPedido.getModel();
    }

    public void setControlador(CompraController controlador) {
        this.controlador = controlador;
    }

    public void setCampoMonto(String format) {
        labelMonto.setText(format);
    }

    public JComboBox getComboClientes() {
        return comboClientes;
    }
    
}
